/**
 * @author Johann Prieur
 */
package mygui;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;

import utils.*;

public abstract class Properties extends JFrame  implements ActionListener,
							    WindowListener
{

    private JButton _cancel;
    private JButton _apply;
    private JButton _ok;

    static enum Type { wireless, base, obstacle, properties; }

    public Properties()
    {
	setResizable(false);
	this.addWindowListener(this);
	setLayout(new BorderLayout());
	
	JPanel buttons = new JPanel();
	buttons.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
	_cancel = new JButton("Cancel");
	_cancel.addActionListener(this);
	buttons.add(_cancel);
	_apply = new JButton("Apply");
	_apply.addActionListener(this);
	buttons.add(_apply);
	_ok = new JButton("Ok");
	_ok.addActionListener(this);
	buttons.add(_ok);
	add("South", buttons);	
    }

    public void actionPerformed(ActionEvent e)
    {
	Component source = (Component)e.getSource();
	if(source == _cancel)
	    {
		dispose();
	    }
	else if(source == _apply)
	    {
		apply();
	    }
	else if(source == _ok)
	    {
		apply();
		MonIHM.instance._display.repaint();
		dispose();
	    }
    }

    /**
     * Physically applies the changes in the properties
     * to the object
     */
    abstract public void apply();

    public void windowActivated(WindowEvent e){}
    public void windowClosed(WindowEvent e){}
    public void windowClosing(WindowEvent e)
    {
	dispose();
    }
    public void windowDeactivated(WindowEvent e){}
    public void windowDeiconified(WindowEvent e){}
    public void windowIconified(WindowEvent e){}
    public void windowOpened(WindowEvent e){}

    public class ObjectIdCard extends JPanel
    {
	private JLabel _icon;
	private JLabel _name;

	/**
	 * Display an Id card with the given informations
	 * @param type type of the object
	 * @param name the name of the object
	 * @param comment a comment on the object
	 * @param location a string representation of its location
	 * @param lock represents the lock status of the properties
	 */
	public ObjectIdCard(Type type,
			    String name, 
			    String comment)
	{
	    setLayout(new BorderLayout());
	    setBorder(new EtchedBorder(EtchedBorder.RAISED));//LOWERED));

	    switch(type)
		{
		case wireless:
		    _icon = new JLabel(UIM.createImageIcon("images/wireless.png",""));
		    break;
		case base:
		    _icon = new JLabel(UIM.createImageIcon("images/base.png",""));
		    break;
		case obstacle:
		    _icon = new JLabel(UIM.createImageIcon("images/rectangle.png",""));
		    break;
		case properties:
		    _icon = new JLabel(UIM.createImageIcon("images/properties.png",""));
		    break;
		}

	    _name = new JLabel("<html><b>" +
			       name +
			       "</b><br><font size=-2>" +
			       comment +
			       "</font></html>");

	    add("West", _icon);
	    add("Center", _name);

	    setBackground(new Color(217, 196, 149));
	}

	
    }

}
